﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;

using System.Windows.Input;

using FXnaWpfBase;

using GWApplication;



namespace GWPresentation
{
    public static class CommonCommandsBinder
    {




        /// <summary>
        /// 将命令绑定到窗体
        /// </summary>
        /// <param name="window"></param>
        public static void BindCommandsToWindow(Window window)
        {

            //绑定NewProject命令
            CommandBinding cbNew = new CommandBinding();
            cbNew.Command = AppCommands.NewProject;
            cbNew.CanExecute += new CanExecuteRoutedEventHandler(cbNew_CanExecute);
            cbNew.Executed += new ExecutedRoutedEventHandler(cbNew_Executed);
            window.CommandBindings.Add(cbNew);

            //绑定OpenProject命令
            CommandBinding cbOpen = new CommandBinding();
            cbOpen.Command = AppCommands.OpenProject;
            cbOpen.CanExecute += new CanExecuteRoutedEventHandler(cbOpen_CanExecute);
            cbOpen.Executed += new ExecutedRoutedEventHandler(cbOpen_Executed);
            window.CommandBindings.Add(cbOpen);

            //绑定SaveProject命令
            CommandBinding cbSave = new CommandBinding();
            cbSave.Command = AppCommands.SaveProject;
            cbSave.CanExecute += new CanExecuteRoutedEventHandler(cbSave_CanExecute);
            cbSave.Executed += new ExecutedRoutedEventHandler(cbSave_Executed);
            window.CommandBindings.Add(cbSave);

            //绑定CloseProject命令
            CommandBinding cbClose = new CommandBinding();
            cbClose.Command = AppCommands.CloseProject;
            cbClose.CanExecute += new CanExecuteRoutedEventHandler(cbClose_CanExecute);
            cbClose.Executed += new ExecutedRoutedEventHandler(cbClose_Executed);
            window.CommandBindings.Add(cbClose);






        }



        static void cbNew_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ApplicationService.CurrentService.NewProject();
        }

        static void cbNew_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }

        static void cbSave_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ApplicationService.CurrentService.SaveProject();
        }

        static void cbSave_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;

            }
        }
        static void cbOpen_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ApplicationService.CurrentService.OpenProject();
        }

        static void cbOpen_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
            e.Handled = true;
        }

        static void cbClose_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            ApplicationService.CurrentService.CloseProject();
        }

        static void cbClose_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (!ProjectService.CurrentService.BNullProj)
            {
                e.CanExecute = true;
                e.Handled = true;
            }

        }



        public static void BindKeyToWindow(Window window)
        {



        }


    }
}
